package com.approval.approvalapp.center.acitivty;

import android.app.ProgressDialog;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.BjtjSjList;
import com.approval.approvalapp.center.adapter.BjtjSjAdapter;
import com.approval.approvalapp.center.centerfragment.BjtjsjFragment;
import com.approval.approvalapp.util.SpUtil;
import com.approval.approvalapp.util.base.BaseActivity;
import com.approval.approvalapp.util.net.NetRequsetUtil;
import com.approval.approvalapp.util.net.interfacepac.NetDownResponse;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class BjtjXqActivity extends BaseActivity {

    @Bind(R.id.back_iv)
    ImageView backIv;
    @Bind(R.id.titleTv1)
    TextView titleTv1;
    @Bind(R.id.rv)
    RecyclerView rv;
    private String id;

    @Override
    public int getLayoutId() {
        return R.layout.activity_bjtj_xq;
    }

    @Override
    public void initView() {
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = this.getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            this.getWindow().setStatusBarColor(Color.TRANSPARENT);
        }


    }

    @Override
    public void initData() {

        id = getIntent().getStringExtra("id");

        final ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setMessage("正在请求数据");
        progressDialog.show();

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("region_code" , id);
        NetRequsetUtil.getInstance().netRequestPostJson("v1/user/queryDeptBJInfo", jsonObject.toString(),new NetDownResponse() {
            @Override
            public void success(String str) {
                List<BjtjSjList> bjtjSjLists = JSON.parseArray(str, BjtjSjList.class);
                rv.setLayoutManager(new LinearLayoutManager(BjtjXqActivity.this));
                BjtjSjAdapter bjtjSjAdapter = new BjtjSjAdapter();
                rv.setAdapter(bjtjSjAdapter);
                bjtjSjAdapter.setBjtjSjLists(bjtjSjLists);

            }

            @Override
            public void errowithresponse(String str) {
                if (progressDialog != null){
                    progressDialog.dismiss();
                }
            }

            @Override
            public void erro() {
                if (progressDialog != null){
                    progressDialog.dismiss();
                }
            }

            @Override
            public void finish() {
                if (progressDialog != null){
                    progressDialog.dismiss();
                }
            }
        });

    }


    @OnClick(R.id.back_iv)
    public void onViewClicked() {
        finish();
    }
}
